package com.sk.bilibili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sk.bilibili.bean.Favorites;
import com.sk.bilibili.other.R;
import com.sk.bilibili.service.FavoritesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 邵康
 * @date 2021/11/25 14:29
 */
@CrossOrigin
@RestController
@RequestMapping("/favorites")
@Api(tags = "收藏夹")
public class FavoritesController {

    @Autowired
    private FavoritesService favoritesService;

    @ApiOperation("添加收藏夹 名字  必须")
    @PostMapping("/add")
    public R<Void> add(Favorites favorites) {
        return favoritesService.add(favorites);
    }

    @ApiOperation("删除收藏夹")
    @GetMapping("/delete")
    public R<Void> delete(Integer id) {
        return favoritesService.delete(id);
    }

    @ApiOperation("更新收藏夹")
    @PostMapping("/update")
    public R<Void> update(Favorites favorites) {
        return favoritesService.update(favorites);
    }

    @ApiOperation("获取所有收藏夹  size 大小  memberId 目标用户  若为null 为当前用户")
    @GetMapping("/getAll")
    public R<List<Favorites>> getAll(@RequestParam(required = false) Integer memberId,
                                     @RequestParam(required = false) Integer size) {
        return favoritesService.getAll(memberId, size);
    }

    @ApiOperation("page")
    @GetMapping("/page")
    public R<IPage<Favorites>> page(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer size) {
        return favoritesService.page(page, size);
    }

    @ApiModelProperty("获取每个收藏夹信息  包含创建用户信息")
    @GetMapping("/getFavorites")
    public R<Favorites> getFavorites(Integer id){
        return favoritesService.getFavorites(id);
    }

}
